import {GetUserinfo} from "../../api/common";

export default {
    namespaced: true,
    state: {
        userinfo: null,
    },
    mutations: {
        // 保存用户信息
        setUserinfo(state, data) {
            state.userinfo = data
        },
        // 清除用户信息
        clearUserinfo(state) {
            state.userinfo = null
        },
    },
    actions: {
        //获取用户数据
        async getUserinfo({ commit }){
            const { code, data } = await GetUserinfo()
            if (+code === 200) {
                commit('setUserinfo', data)
                return Promise.resolve(data)
            }
        },
    },
}